Namespace:
System.Collections.Concurrent
Assembly:
System.Threading (in System.Threading.dll)
Syntax
Visual Basic (Declaration) |
---|
Public Function GetOrAdd ( _
key As TKey, _
valueFactory As Func(Of TKey, TValue) _
) As TValue |
C# |
---|
public TValue GetOrAdd(
TKey key,
Func<TKey, TValue> valueFactory
) |
Parameters
- key
- Type: TKey
The key of the element to add.
- valueFactory
- Type: System..::.Func<(Of <(TKey, TValue>)>)
The function used to generate a value for the key
Return Value
The value for the key. This will be either the existing value for the key if the
key is already in the dictionary, or the new value for the key as returned by valueFactory
if the key was not in the dictionary.
Exceptions
Exception | Condition |
---|
System..::.ArgumentNullException | key is a null reference
(Nothing in Visual Basic). |
System..::.ArgumentNullException | valueFactory is a null reference
(Nothing in Visual Basic). |
System..::.OverflowException | The dictionary contains too many
elements. |
See Also